﻿Public Class masoccupation
    Private occupationID = Nothing
    Private occupationDescription = Nothing
    Private occupationStatus = Nothing
    Private selectMasoccupation = "SELECT `occid` as 'รหัสอาชีพ',`occupationdesc` as 'อาชีพ' ,`status` as 'สถานะการเปิดใช้งาน' FROM masoccupation "
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property occupationID_ As Integer
        Get
            Return occupationID
        End Get
        Set(value As Integer)
            occupationID = value
        End Set
    End Property

    Property occupationDescription_ As String
        Get
            Return occupationDescription
        End Get
        Set(value As String)
            occupationDescription = value
        End Set
    End Property

    Property occupationStatus_ As Boolean
        Get
            Return occupationStatus
        End Get
        Set(value As Boolean)
            If value = True Then
                occupationStatus = 1
            Else
                occupationStatus = 0
            End If
        End Set
    End Property

    Property selectMasoccupation_ As String
        Get
            Return selectMasoccupation
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasoccupationData()
        If occupationDescription <> "" Then
            If TypeOf occupationDescription Is String Then
                If connect.GetTable("SELECT occupationdesc FROM masoccupation WHERE occupationdesc = '" & occupationDescription & "'").Rows.Count > 0 Then
                    MsgBox("มีข้อมูลอาชีพนี้อยู่ในระบบแล้ว")
                Else
                    Try
                        connect = CONDB.NewConnection()
                        'connectlocal = conlocal.NewConnection()
                        Dim occuID As Integer

                        occuID = connect.ExecuteScalar("INSERT INTO masoccupation (occupationdesc, status) VALUES ('" & occupationDescription & "', '" & occupationStatus & "'); SELECT LAST_INSERT_ID();")
                        'connectlocal.ExecuteNonQuery("INSERT INTO MASOCCUPATION (OCCID, OCCUPATIONDESC, STATUS) VALUES ('" & occuID & "', '" & occupationDescription & "', '" & occupationStatus & "')")
                        MsgBox("ท่านได้ทำการเพิ่มข้อมูลอาชีพเรียบร้อยแล้ว")
                    Catch ex As Exception
                        MsgBox("มีเลขอาชีพนี้อยู่ในระบบอยู่แล้ว" & vbCrLf & ex.Message)
                    End Try
                    connect.Dispose()
                    'connectlocal.Dispose()
                End If
            Else
                MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
            End If
        Else
            MsgBox("ท่านต้องทำการกรอกข้อมูลให้ครบถ้วน")
        End If
    End Sub

    Public Sub editMasoccupationData()
        If occupationID > 0 And occupationDescription <> "" Then
            If TypeOf occupationDescription Is String Then
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()

                    connect.ExecuteNonQuery("UPDATE masoccupation SET occupationdesc = '" & occupationDescription & "', status = '" & occupationStatus & "' WHERE occid = '" & occupationID & "'")
                    'connectlocal.ExecuteNonQuery("UPDATE MASOCCUPATION SET OCCUPATIONDESC = '" & occupationDescription & "', STATUS = '" & occupationStatus & "' WHERE OCCID = '" & occupationID & "'")
                    MsgBox("ท่านได้ทำการแก้ไขข้อมูลอาชีพเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox("มีอาชีพนี้อยู่ในระบบอยู่แล้ว" & vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            Else
                MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
            End If
        Else
            MsgBox("ท่านต้องทำการกรอกข้อมูลให้ครบถ้วน")
        End If
    End Sub

End Class
